package com.og.backingbean;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

/**
 * @author Renaud DIANA
 *
 */
@Entity
@NamedQueries({@NamedQuery(name = "Module.findAll", query = "SELECT m FROM Module m ORDER BY m.idModule ASC")})
public class Module implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@NotNull
	@NotEmpty
	@Size(max = 50)
	@Column(nullable = false, length = 50)
	private String idModule;
	@NotNull
	@NotEmpty
	@Size(max = 50)
	@Column(nullable = false, length = 50)
	private String name;
	private String toDo;
	private String comments;
	@NotNull
	@NotEmpty
	@Size(max = 50)
	@Column(nullable = false, length = 50)
	private String version;
	@NotNull	
	@Past
	@Column(nullable = false)
	@Temporal(TemporalType.DATE)
	private Date date;
	@Column(columnDefinition = "Decimal(6,2) default '0.00'")
	private float price;
	@ManyToOne
	@JoinColumn(nullable = false)
	private Type type;
	@OneToMany(mappedBy = "module", cascade = CascadeType.ALL)
	@JoinColumn(name = "module_idmodule")	
	private List<ModuleHistory> listModuleHistory;
	@OneToMany(mappedBy = "module", cascade = CascadeType.ALL)
	@JoinColumn(name = "module_idmodule")	
	private List<Composition> listComposition;
	@OneToMany(mappedBy = "module", cascade = CascadeType.ALL)
	@JoinColumn(name = "module_idmodule")	
	private List<TimeSheet> listTimeSheet;
	
	/**
	 * Default constructor
	 */
	public Module() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((idModule == null) ? 0 : idModule.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Module other = (Module) obj;
		if (idModule == null) {
			if (other.idModule != null)
				return false;
		} else if (!idModule.equals(other.idModule))
			return false;
		return true;
	}

	public String getIdModule() {
		return idModule;
	}

	public void setIdModule(String idModule) {
		this.idModule = idModule;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getToDo() {
		return toDo;
	}

	public void setToDo(String toDo) {
		this.toDo = toDo;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}
	
	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public List<ModuleHistory> getListModuleHistory() {
		return listModuleHistory;
	}

	public void setListModuleHistory(List<ModuleHistory> listModuleHistory) {
		this.listModuleHistory = listModuleHistory;
	}

	public List<Composition> getListComposition() {
		return listComposition;
	}

	public void setListComposition(List<Composition> listComposition) {
		this.listComposition = listComposition;
	}

	public List<TimeSheet> getListTimeSheet() {
		return listTimeSheet;
	}

	public void setListTimeSheet(List<TimeSheet> listTimeSheet) {
		this.listTimeSheet = listTimeSheet;
	}

}
